<template>
	<view class="index">
		<musichead title="MusicIndex" :icon="false"></musichead>
		<view class="container">
			<scroll-view scroll-y="true">
				<view class="index-search" @tap="handleToSearch">
					<text class="iconfont iconsearch"></text>
					<input type="text" placeholder="搜索歌曲" />
				</view>
				<view v-if="isLoading">
					<m-for-skeleton :avatarSize="200" :row="3" :loading="isLoading" isarc="square"
						v-for="(item,key) in 4" :titleStyle="{}" :title="false" :key="key">
					</m-for-skeleton>
				</view>
				<view class="index-list" v-else>
					<!-- <view class="index-list-item">
						<view class="index-list-img">
							<image src="../../static/wangyiyunyinyue.png" mode=""></image>
							<text>每天更新</text>
						</view>
						<view class="index-list-text">
							<view>1.与我无关 - 阿冗</view>
							<view>1.与我无关 - 阿冗</view>
							<view>1.与我无关 - 阿冗</view>
						</view>
					</view> -->
					<view class="index-list-item" v-for="(item,index) in topList" :key="index"
						@tap="handleToList(item.listId)">
						<view class="index-list-img">
							<image :src="item.coverImgUrl" mode=""></image>
							<text>{{ item.updateFrequency }}</text>
						</view>
						<view class="index-list-text">
							<view v-for="(item,index) in item.tracks" :key="index">{{ index + 1 }}.{{ item.first }} -
								{{ item.second }}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import '@/common/iconfont.css';
	import musichead from '../../components/musichead/musichead.vue'
	import {
		topList
	} from '../../common/api.js'
	import mForSkeleton from "@/components/m-for-skeleton/m-for-skeleton"
	export default {
		data() {
			return {
				topList: [],
				isLoading: true
			}
		},
		components: {
			musichead,
			mForSkeleton
		},
		onLoad() {
			topList().then((res) => {
				if (res.length) {
					setTimeout(() => {
						this.topList = res;
						this.isLoading = false;
					}, 1000);
				}
			});
		},
		methods: {
			handleToList(listId) {
				uni.navigateTo({
					url: '/pages/list/list?listId=' + listId
				});
			},
			handleToSearch() {
				uni.navigateTo({
					url: '/pages/search/search'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		background-image: linear-gradient(120deg, #fdfbfb 0%, #ebedee 100%);

		.index-search {
			display: flex;
			align-items: center;
			height: 70rpx;
			margin: 50rpx 30rpx 30rpx 30rpx;
			background: #f7f7f7;
			border-radius: 50rpx;

			text {
				font-size: 26rpx;
				margin-right: 26rpx;
				margin-left: 28rpx;
			}

			input {
				font-size: 28rpx;
				flex: 1;
			}
		}

		.index-list {
			margin: 0 30rpx;

			.index-list-item {
				display: flex;
				margin-bottom: 34rpx;

				.index-list-img {
					width: 212rpx;
					height: 212rpx;
					position: relative;
					border-radius: 30rpx;
					overflow: hidden;
					margin-right: 22rpx;

					image {
						width: 100%;
						height: 100%;
					}

					text {
						position: absolute;
						left: 12rpx;
						bottom: 16rpx;
						color: #fff;
						font-size: 20rpx;
					}
				}

				.index-list-text {
					width: 50%;
					font-size: 24rpx;
					line-height: 66rpx;

					view {
						white-space: nowrap;
						/* 文本不换行 */
						overflow: hidden;
						/* 隐藏溢出部分 */
						text-overflow: ellipsis;
						/* 超出部分显示省略号 */
					}
				}
			}
		}
	}
</style>